home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ASM-A.ZIP / ATTR.ASM < prev    next >
Assembly Source File  |  1986-03-17  |  7KB  |  216 lines

  1. ;    ATTR.ASM -- File Attribute Utility
  2. ;    ==================================
  3.  
  4. CSEG        Segment
  5.         Assume    CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
  6.         Org    0080h
  7. Parameter    Label    Byte        ; Parameter is here
  8.         Org    0100h
  9. Entry:        Jmp    Begin        ; Entry Point
  10.  
  11. ;    Most Data (some more at end of program)
  12. ;    ---------------------------------------
  13.  
  14.         db    "ATTR (C) 1986, Ziff-Davis Publishing Co.",1Ah
  15.         db    " Programmed by Charles Petzold ",1Ah
  16. SyntaxMsg    db    "Syntax: ATTR [+A|-A] [+S|-S] [+H|-H] [+R|-R] "
  17.         db    "[drive:][path]filename",13,10
  18.         db    "             Archive System  Hidden  Read-Only$"   
  19. DosVersMsg    db    "ATTR: Needs DOS 2.0 +$"
  20. FlagErrMsg    db    "ATTR: Incorrect flag$"
  21. FileSpecMsg    db    "ATTR: Incorrect File Spec$"
  22. Delimiters    db    9,' ,;=',13
  23. FlagList    db    "ASHR", 20h, 04h, 02h, 01h
  24. AllFlagList    db    "    $Arc $Dir $$$$$$Sys $Hid $R-O$"
  25. ChangeFlag    db    0
  26. AndAttrBits    db    0
  27. OrAttrBits    db    0
  28. SearchString    dw    ?
  29. AppendFileName    dw    ?
  30.  
  31. ;    Check DOS Version
  32. ;    -----------------
  33.  
  34. Begin:        Mov    AH, 30h            ; Check for DOS Version
  35.         Int    21h            ;   through DOS call
  36.         Cmp    AL, 2            ; See if it's 2.0 or above
  37.         Jae    DosVersOK        ; If so, continue
  38.  
  39.         Mov    DX, Offset DosVersMsg    ; Error message
  40. ErrorExit:    Mov    AH, 9            ; Print String function call
  41.         Int    21h            ; Do it
  42.         Int    20h            ; And exit prematurely
  43.  
  44. ;    Parse Command Line to get file specification
  45. ;    --------------------------------------------
  46.  
  47. DosVersOK:    Mov    SI, 1+Offset Parameter    ; Parameter string pointer
  48.         Cld                ; Directions forward
  49.  
  50. FlagSearch:    Lodsb                ; Get Byte
  51.         Mov    DI, Offset Delimiters    ; Check if delimiter
  52.         Mov    CX, 5            ; Five delimiters to check
  53.         Repne    Scasb            ; Scan the string
  54.         Je    FlagSearch        ; If delimiter, circle back
  55.         Mov    DX, Offset SyntaxMsg    ; Possible error msg 
  56.         Cmp    AL, 13            ; If carriage return, no file
  57.         Je    ErrorExit        ;   so exit with message
  58.                 
  59.         Mov    DI, Offset OrAttrBits    ; Pointer to plus flag saver
  60.         Cmp    AL, '+'            ; See if plus sign
  61.         Je    PlusOrMinus        ; If so, save the bit
  62.         Mov    DI, Offset AndAttrBits    ; Pointer to minus flag saver
  63.         Cmp    AL, '-'            ; See if minus sign
  64.         Jne    MustBeFile        ; If not, it must be file name
  65.  
  66. PlusOrMinus:    Mov    [ChangeFlag],-1        ; Set for changing
  67.         Lodsb                ; Get the next byte
  68.         And    AL, 0DFh        ; Capitalize it
  69.         Mov    BX, Offset FlagList    ; List for scanning
  70.         Mov    CX, 4            ; Scan for A, S, H, and R
  71.  
  72. SearchList:    Cmp    AL, [BX]        ; See if a match
  73.         Jz    FoundFlag        ; If so, proceed to save    
  74.         Inc    BX            ; Kick up pointer 
  75.         Loop    SearchList        ; And loop around for next
  76.         Mov    DX, Offset FlagErrMsg    ; Otherwise, set message 
  77.         Jmp    ErrorExit        ; And terminate
  78.  
  79. FoundFlag:    Mov    AL, [BX + 4]        ; Get bit mask
  80.         Or    [DI], AL        ; Turn saved bit on
  81.         Jmp    FlagSearch        ; And continue looking
  82.  
  83. MustBeFile:    Not    [AndAttrBits]        ; Invert bits for turn off
  84.         Mov    [SearchString], SI    ; Save file name pointer
  85.         Dec    [SearchString]        ; Actually one byte lower
  86.  
  87. EndSearch:    Lodsb                ; Get Byte
  88.         Mov    DI, Offset Delimiters    ; Check if delimiter
  89.         Mov    CX, 6            ; Six delimiters including CR
  90.         Repne    Scasb            ; Scan the string
  91.         Jne    EndSearch        ; If not delimiter, keep going
  92.  
  93. ;    Transfer Search String down at end of program
  94. ;    ---------------------------------------------
  95.  
  96.         Dec    SI            ; Points after file spec
  97.         Mov    Byte Ptr [SI], 0    ; Make it ASCIIZ string
  98.         Mov    CX, SI            ; CX points to end
  99.         Mov    SI, [SearchString]    ; SI points to beginning
  100.         Sub    CX, SI            ; Now CX is length of it
  101.         Mov    DI, Offset PathAndFile    ; Destination of string
  102.         Mov    [AppendFileName], DI    ; Save it here also
  103.  
  104. SearchTrans:    Lodsb                ; Get byte of search string
  105.         Stosb                ; And save it down below
  106.         Cmp    AL, ':'            ; See if drive marker
  107.         Je    PossibleEnd        ; If so, take note of it
  108.         Cmp    AL, '\'            ; See if path separator
  109.         Jne    NextCharacter          ; If not, skip next code
  110.  
  111. PossibleEnd:    Mov    [AppendFileName], DI    ; This is the new end
  112. NextCharacter:    Loop    SearchTrans        ; Do it again until done
  113.  
  114. ;    Find Files from Search String
  115. ;    -----------------------------
  116.  
  117.         Mov    DX, Offset DTABuffer    ; Set File Find buffer
  118.         Mov    AH, 1Ah            ;   by calling DOS
  119.         Int    21h
  120.  
  121.         Mov    DX, [SearchString]    ; Search string
  122.         Mov    CX, 16h            ; Search Everything
  123.         Mov    AH, 4Eh            ; Find first file 
  124.  
  125. FindFile:    Int    21h            ; Call DOS to find file
  126.         Jnc    Continue        ; If no error continue
  127.         Cmp    AX, 18            ; If not "no more files" error
  128.         Jnz    FindError        ;   print error message
  129.         Jmp    NoMoreFiles        ; Now get out of the loop
  130.  
  131. FindError:    Mov    DX, Offset FileSpecMsg    ; Error message for file spec
  132.         Jmp    ErrorExit        ; Exit and print message
  133.  
  134. Continue:    Mov    SI, 30+Offset DTABuffer    ; Points to filename
  135.         Cmp    Byte Ptr [SI], '.'    ; See if "dot" entry
  136.         Jnz    FileIsOK        ; If not, continue
  137.         Jmp    FindNextFile        ; If so, skip it
  138.  
  139. FileIsOK:    Mov    DI, [AppendFileName]    ; Destination of file name
  140.         Mov    CX, 14            ; Number of bytes to display
  141.  
  142. TransferName:    Lodsb                ; Get the byte in file name
  143.         Stosb                ; Save it
  144.         Or    AL, AL            ; See if terminating zero
  145.         Jz    PadWithBlanks        ; If so, display blanks
  146.         Call    DisplayChar        ; Display the character
  147.         Loop    TransferName        ; And loop back around
  148.  
  149. PadWithBlanks:    Mov    AL, ' '            ; Pad names with blanks
  150.         Call    DisplayChar
  151.         Loop    PadWithBlanks        ; And loop until CX is zero
  152.  
  153. ;    Change And Display File Attributes
  154. ;    ---------------------------------- 
  155.  
  156.         Mov    DX, Offset PathAndFile    ; Points to ASCIIZ string
  157.         Test    [ChangeFlag], -1    ; See if changing attributes
  158.         Jz    DisplayIt        ; If not, just display them 
  159.  
  160.         Mov    AX, 4300h        ; Get file attribute
  161.         Int    21h            ;   by calling DOS
  162.         And    CL, 27h            ; Zero out some bits
  163.         And    CL, [AndAttrBits]    ; Turn off some bits
  164.         Or    CL, [OrAttrBits]    ; Turn on some bits
  165.         Mov    AX, 4301h        ; Set file attribute
  166.         Int    21h            ;   by calling DOS
  167.  
  168. DisplayIt:    Mov    AX, 4300h        ; Get file attribute
  169.         Int    21h            ;   by calling DOS
  170.         Mov    BL, CL            ; BL is attributes
  171.         Or    BL, 08h            ; Turn on Volume bit
  172.         Shl    BL, 1            ; Shift to get rid of
  173.         Shl    BL, 1            ;   unused bits
  174.         Mov    CX, 6            ; Number of bits left
  175.         Mov    DX, 5+Offset AllFlagList; Storage of abbreviations
  176.         
  177. AttrListLoop:    Push    DX            ; Save abbreviation pointer
  178.         Shl    BL, 1            ; Shift bit into carry
  179.         Jc    FlagIsOn        ; See if it's on
  180.         Mov    DX, Offset AllFlagList    ; If not, print blanks
  181.  
  182. FlagIsOn:    Mov    AH, 9            ; Print string
  183.         Int    21h            ;   by calling DOS
  184.         Pop    DX            ; Get back abbreviation ptr
  185.         Add    DX, 5            ; Kick up for next bit
  186.         Loop    AttrListLoop        ; And loop around
  187.         Mov    AL, 13            ; Print carriage return
  188.         Call    DisplayChar
  189.         Mov    AL, 10            ; Print line feed
  190.         Call    DisplayChar
  191.  
  192. FindNextFile:    Mov    AH, 4Fh            ; Find next file
  193.         Jmp    FindFile        ; By looping around
  194.  
  195. NoMoreFiles:    Int    20h            ; Terminate
  196.  
  197. ;    SUBROUTINE: Display Character in AL
  198. ;    -----------------------------------
  199.  
  200. DisplayChar:    Push    AX
  201.         Push    DX
  202.         Mov    DL, AL            ; Move character to DL
  203.         Mov    AH, 2            ; Display it
  204.         Int    21h            ;   by calling DOS
  205.         Pop    DX
  206.         Pop    AX
  207.         Ret
  208.  
  209. ;    Some data stored at end to cut down COM size
  210. ;    --------------------------------------------
  211.  
  212. DTABuffer    Label    Byte            ; For file find calls
  213. PathAndFile    equ    DTABuffer + 43        ; For file path and name 
  214. CSEG        EndS                ; End of the segment
  215.         End    Entry            ; Denotes entry point
  216.